package com.zzj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.BoxBean;
import com.zzj.dao.BoxDao;
import com.zzj.dao.ProductDao;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BoxServiceImpl implements BoxService {
    @Resource
    private BoxDao boxDao;
    @Resource
    private ProductDao productDao;

    @Override
    public PageInfo<BoxBean> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<BoxBean> all = boxDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public Result updateBox(BoxBean boxBean) {
        boxBean.setBstate("1");
        int i1 =boxDao.updateBox(boxBean);
        int i2 = productDao.updateProductStateFid(boxBean.getPid(), "7",boxBean.getTid());
        if (i1 == 1 && i2 == 1){
            return new Result();
        }
        return new Result(false, StatusCode.ERROR,"操作失败");
    }
}
